﻿namespace Anley.DomainDrivenDesign.Contract.Extension;

/// <summary>
/// 数组扩展类
/// </summary>
public static class ArrayExtension
{
    /// <summary>
    /// 向数组头部添加元素
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="array"></param>
    /// <param name="value"></param>
    public static T[] Unshift<T>(
        this T[] array,
        T value)
    {
        if (array == null || array.Length == 0)
            return [value];
        var newArray = new T[array.Length + 1];
        newArray[0] = value;
        Array.Copy(array, 0, newArray, 1, array.Length);
        return newArray;
    }
}